<template>
  <uv-tabbar :value="tabbar.name" @change="change" :fixed="true" activeColor="#3775F6"
             inactiveColor="rgb(0,0,0,.9)">
    <uv-tabbar-item text="首页" name="home">
      <template #inactive-icon>
        <view class="iconfont icon-home"></view>
      </template>
      <template #active-icon>
        <view class="iconfont icon-home active-color"></view>
      </template>
    </uv-tabbar-item>
    <uv-tabbar-item text="工作台" name="applicationCenter">
      <template #inactive-icon>
        <view class="iconfont icon-workbench"></view>
      </template>
      <template #active-icon>
        <view class="iconfont icon-workbench active-color"></view>
      </template>
    </uv-tabbar-item>
    <uv-tabbar-item text="我的" name="user">
      <template #inactive-icon>
        <view class="iconfont icon-mine"></view>
      </template>
      <template #active-icon>
        <view class="iconfont icon-mine active-color"></view>
      </template>
    </uv-tabbar-item>
  </uv-tabbar>
</template>
<script setup>
import {getCurrentInstance} from "vue";
import config from '@/common/config'
const pcoLawIndexPermissions = config.PCO_LAW_INDEX_PERMISSIONS;
const permissionsList = uni.getStorageSync('permissions');
const props = defineProps({
  type: {         // 校园/供应商/配餐单位
    type: String,
    default: ''
  },
})
const {proxy} = getCurrentInstance();
const {tabbar} = proxy.store();
let change = name => {
  tabbar.$patch(state => {
    state.name = name;
    if(props.type) {
      state.type = props.type;
    }
  })

  switch (name) {
    case 'home':
      if (permissionsList && permissionsList.includes(pcoLawIndexPermissions)) {
        uni.switchTab({
          url: '/pages/index/pcoLawIndex'
        });
      }else{
        uni.switchTab({
          url: '/pages/index/schoolIndex'
        });
      }
      break;
    case 'applicationCenter':
      uni.switchTab({
        url: '/pages/application/applicationCenter'
      });
      break;
    case 'user':
      uni.switchTab({
        url: '/pages/user/userInfo'
      });
      break;
    default:
      break;
  }
}

</script>
<style scoped lang="scss">
.active-color {
  color: #3775F6;
}
</style>
